from selenium.webdriver.common.by import By
from pages.base_page import Page


class ChatWindowPage(Page):
    ele_title = (By.ID, u'page-chatWindow-title')
    ele_error = (By.XPATH, u'//div[@role="alert"]')

    ele_agent_info = (By.XPATH, u"//button[@value='agent']")
    ele_banner_image = (By.XPATH, u"//button[@value='banner']")
    ele_agent_avatar = (By.XPATH, u"//button[@value='logo']")

    # type
    ele_type_embedded = (By.XPATH, u"//button[@value='embeddedChatWindow']")
    ele_type_popup = (By.XPATH, u"//button[@value='popupChatWindow']")

    ele_options_for_vistors = (By.XPATH, u"//p[@data-tag='cardTitle' and text()='Options for Visitors']")
    ele_save_button = (By.XPATH, u"(//button[@data-tag='formButton' and @tabindex='0'])[1]")

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def check_page_eles(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_agent_info).is_enabled()
        self.find_element(*self.ele_banner_image).is_enabled()
        self.find_element(*self.ele_agent_avatar).is_enabled()
        self.find_element(*self.ele_type_embedded).is_enabled()
        self.find_element(*self.ele_type_popup).is_enabled()
        self.find_element(*self.ele_options_for_vistors).is_enabled()

    def chat_window_button_save(self):
        self.click(self.ele_agent_info)
        self.click(self.ele_type_embedded)
        self.click(self.ele_options_for_vistors)
        self.click(self.ele_save_button)
